#include <iostream>
#include <algorithm>
using namespace std;

bool cmp(string a,string b)
{
	return a.length()<b.length();
}
int main()
{
	int jishu=1;
	int t;
	while(cin>>t){
		if(t==0) break;
		string s[100000];
		string result[10000];
		for(int i=0;i<t;i++) cin>>s[i];
		sort(s,s+t,cmp);
		int front=0;
		int rear=t-1;
		for(int j=0;j<t;j++){
			if(j%2==0){
				result[front]=s[j];
				front++;
			}
			else {
				result[rear]=s[j];
				rear--;
			}
		}
		cout<<"SET "<<jishu<<endl;
		for(int k=0;k<t;k++){
			cout<<result[k]<<endl;
		}
		jishu++;
	}
}
